<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 4/12/2024
  Time: 1:48 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
用户名：<input type="text" name="name" id="name"/> <span id="nameSpan"></span><br/>
密码：<input type="text" name="password" id="password"/><br/>
<input type="button" value="登录">

<script src="/static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
<script>
    $(function() {
        $('#name').blur(function() {
            //this
            $.post(
                '/ajax2',
                {'name': $(this).val()},
                function(jsonObj) {
                    console.log(jsonObj);
                    //{exist: true, msg: '此用户已经存在，请更换一个'}
                    if (jsonObj.exist) {
                        $('#nameSpan').html(jsonObj.msg);
                        $('#nameSpan').css('color', 'red');
                    } else {
                        $('#nameSpan').html(jsonObj.msg);
                        $('#nameSpan').css('color', 'green');
                    }
                },
                'json'
            );
        });
    });
</script>
</body>
</html>
